package demo1;

import com.sun.xml.internal.bind.v2.runtime.output.StAXExStreamWriterOutput;

class OutterClass {
    public int data1 = 1;
    public static int data2 = 2;
    private int data3 = 3;
    class InnerClass{
        public int data1 = 111;

        public int data4 = 4;
        //public static int data5;//不可以定义静态的
        public static final int data5 = 5;//编译时确定,已经是一个静态的
        private int data6 = 6;
        public void test() {
            //System.out.println("InnerClass::test()"+data5);已经是静态的
            System.out.println("InnerClass::test()");
            System.out.println(data1);
            System.out.println(OutterClass.this.data1);

            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);//也是可以的，private

        }

    }
    public void test() {
        InnerClass innerClass = new InnerClass();
        innerClass.test();
        System.out.println("OuterCass::test()");
    }
}
class Out {
    public int data1 = 1;
    public static int data2 = 2;
    private int data3 = 3;
    static class InnerClass {//静态内部类相较于实例2内部类的优点就在于：创建静态内部类前，不需要先创建外部类对象，只需要外部类类名
        public int data4 = 4;
        public static int data5 = 5;
        private int data6 = 6;
        public void test() {//
            Out out = new Out();
            //System.out.println(data1);//不能引用
            //因为，这是静态内部类，因此直接访问外部非静态是不可以的，所以直接在内部类生成一个外部类对象来引用
            System.out.println(out.data1);
            System.out.println(data2);
            System.out.println(out.data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);

            System.out.println("InnerClass::test()");

        }
    }
    public void test() {

        System.out.println("OuterCass::test()");
    }
}
interface IA {
    public void test() ;
}
public class Test2 {
    public static void main(String[] args) {
        /*IA a = */new IA() {//相当于你有一个类，实现了IA接口，并且实现了test方法
            @Override
            public void test() {
                System.out.println("这是重写了接口的方法");
            }
        }.test();
        //a.test();
    }
    public static void main2(String[] args) {

        Out.InnerClass innerClass = new Out.InnerClass();
        innerClass.test();
    }
    public static void main1(String[] args) {
        OutterClass outterClass = new OutterClass();
        //OutterClass.InnerClass innerClass = outterClass.new InnerClass();
        OutterClass.InnerClass innerClass = new OutterClass().new InnerClass();

        innerClass.test();
        System.out.println("===================");
        //outterClass.test();

    }
}
